package com.rzjm.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rzjm.api.dao.DeviceDao;
import com.rzjm.api.dao.RegFireCheckDao;
import com.rzjm.api.dao.ShopDao;
import com.rzjm.api.entity.Device;
import com.rzjm.api.entity.RegFireCheck;
import com.rzjm.api.entity.Shop;
import com.rzjm.api.entity.User;
import com.rzjm.api.service.RegFireCheckService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RegFireCheckServiceImpl extends BaseServiceImpl<RegFireCheckDao, RegFireCheck> implements RegFireCheckService {

    @Resource
    private RegFireCheckDao regFireCheckDao;

    @Resource
    private ShopDao shopDao;
    @Resource
    private DeviceDao deviceDao;

    @Override
    public List<RegFireCheck> getRegList(User user,Integer pageIndex,Integer pageSize,Integer type) {
        QueryWrapper<RegFireCheck> qw = new QueryWrapper<>();
        qw.eq("shop_id",user.getShopId());
//        if(type == 0){
//            qw.eq("reg_wx_user_id",user.getId());
//        }else{
//
//        }
        List<RegFireCheck> list = regFireCheckDao.getPageEntityList(qw,pageIndex,pageSize);
        if(list!=null && list.size() > 0){
            for (RegFireCheck regFireCheck : list){
                Device device = deviceDao.selectById(regFireCheck.getDeviceId());
                if(device!=null){
                    regFireCheck.setDeviceName(device.getDeviceName());
                    regFireCheck.setOnlineState(device.getOnlineState());
                }

                Shop shop = shopDao.selectById(regFireCheck.getShopId());
                if(shop!=null){
                    regFireCheck.setShopName(shop.getShopName());
                }
            }
        }
        return list;
    }
}
